package com.caiyi.financial.nirvana.sms.queue;

import com.alibaba.fastjson.JSON;
import com.caiyi.financial.nirvana.sms.entity.SmsAccountBlacklist;
import com.caiyi.financial.nirvana.sms.jedis.JedisKey;
import com.caiyi.financial.nirvana.sms.service.SmsAccountBlacklistService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Mario on 2017/12/20 0020.
 * 黑名单入库队列
 */
@Component
public class AccountBlackListQueue implements IRedisQueue {
    public static final Logger logger = LoggerFactory.getLogger(AccountBlackListQueue.class);

    @Autowired
    private SmsAccountBlacklistService smsAccountBlacklistService;

    @Override
    public String key() {
        return JedisKey.SMS_QUEUE_BLACKLIST_INSERT_DB;
    }

    public void run(List<String> list) {
        if (list == null || list.isEmpty()) {
            return;
        }
        logger.info("AccountBlackListQueue run . key : {}, value : {}", list.get(0), list.get(1));
        SmsAccountBlacklist blackList = JSON.parseObject(list.get(1), SmsAccountBlacklist.class);
        smsAccountBlacklistService.addAccountBlacklist(blackList);
    }

    @Override
    public void interrupt(Exception e) {

    }
}